﻿package com.zit.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.sql.Update;

import com.zit.entity.Berth;

public class BerthDAO extends BaseDAO {
	
	/**
	 * 作者:唐美兰
	 * 功能:根据寝室Id查询寝室下面的所有床号
	 * @return
	 */
	public List<Berth> select(int did,Session s){
		Query query = s.createQuery("select new Berth(b.id,b.name) from Berth b where b.bedroom.id=:did and b.remark='0'").setParameter("did", did);
		return query.list();
	}
	
	/**
	 * 添加或者删除学生：修改床位是否有人住
	 * @param berth
	 * @param s
	 */
	public void updateBerth(Berth berth,Session s){
		Query query = s.createQuery("update Berth set remark=:rem where id=:bid").setParameter("bid", berth.getId()).setParameter("rem", berth.getRemark());
		query.executeUpdate();
	}
}
